package datastructures.tree;

/**
 * 测试二叉树
 *
 * @author hck
 */
public class TestBinaryTree {
    public static void main(String[] args) {
        testPreorderTraverse();
    }

    private static BinaryTree getBinaryTree() {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.Node node1 = new BinaryTree.Node(1);
        BinaryTree.Node node2 = new BinaryTree.Node(2);
        BinaryTree.Node node3 = new BinaryTree.Node(3);
        BinaryTree.Node node4 = new BinaryTree.Node(4);
        BinaryTree.Node node5 = new BinaryTree.Node(5);
        binaryTree.setRoot(node1);
        node1.left = node2;
        node1.right = node3;
        node3.left = node4;
        node3.right = node5;
        return binaryTree;
    }

    private static void testPreorderTraverse() {
        BinaryTree binaryTree = getBinaryTree();
        System.out.println("前序遍历：");
        binaryTree.preorderTraverse();
        System.out.println();
        System.out.println("中序遍历：");
        binaryTree.inOrderTraversal();
        System.out.println();
        System.out.println("后序遍历：");
        binaryTree.postOrderTraverse();
    }
}
